package com.example.student.contorller;

import com.example.student.model.Student;
import com.example.student.service.StudentService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {
    StudentService studentService;
    @GetMapping("/students")
    public List<Student> getAllStudent(){
        return studentService.list();
    }
    @GetMapping("/student/{id}")
    public Student getStudentById(@PathVariable("id") Integer id){
        return studentService.getById(id);
    }
    @PostMapping("/student")
    public String addStudent(@RequestBody Student student){
       if (studentService.save(student)){
           return "添加成功";
       }
       return "添加失败";
    }
    @PutMapping("/student")
    public String updateStudent(@RequestBody Student student){
        if (studentService.updateById(student)){
            return "修改成功";
        }
        return "修改失败";
    }
    @DeleteMapping("/student")
    public String deleteStudent( Integer id){
        if (studentService.removeById(id)){
            return "删除成功";
        }
        return "删除失败";
    }
}
